# system("python SolveHarmonicOscillator1D.py")

file.dir <- "./data/"
i <- 0
print(dir(file.dir))
for(infile in dir(file.dir)) {

    data <- read.csv(file=paste(file.dir,infile,sep=""),head=FALSE,sep=",")
    # now can access each as data$V1 or data$V3

    outfilename = paste("./plots/time_", sprintf("%06d",i), ".pdf", sep="")
    i <- i+1
    
    wvfn <- data$V4 * 3 + 4

    pdf(outfilename) # makes a pdf printing device for plots
    plot(data$V1,data$V2,pch=".",xlab="Position (Bohr)",ylab="Energy (Hartree)",ylim=c(-2,10)) # Plot the Hamiltonian
    points(data$V1,data$V3,pch=".",col="blue") # Plot the "Classical" Potential V
    points(data$V1,wvfn,pch=".",col="red")  # Plot the probability Density
    dev.off() #closes the pdf printing device

}

print("Updated ./plots\nMaking moive...\n")

# then convert *.pdf to a .gif with whichever software one wants (platform-dependent)

#system("convert ./plots/*.pdf SHO.gif")